package com.food.eat.controller;

import com.food.eat.pojo.vo.ShopCatVo;
import com.food.eat.util.FoodResultJson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:RenPu
 * @Date: 2020/7/18 16:49
 * @Version: 1.0
 * @description:
 */

@Api(value = "购物车相关的api接口", tags = {"购物车相关的api接口"})
@RequestMapping("shopcart")
@RestController
public class ShopCatController {


    @ApiOperation(value = "添加商品到购物车", notes = "添加商品到购物车", httpMethod = "POST")
    @PostMapping(value = "add")
    public FoodResultJson add(@RequestParam String userId,
                              @RequestBody ShopCatVo shopcatBO,
                              HttpServletRequest request,
                              HttpServletResponse response) {

        if (StringUtils.isBlank(userId)) {

            FoodResultJson.errMap("");

        }

        System.out.println("打印前端cookie存储的数据，传送到后端------------O(∩_∩)O哈哈~------------" + shopcatBO);

        //TODO 用户登录的状态进行，添加商品到购物车，会同时在后端同步到redis缓存
        return FoodResultJson.ok();
    }


    @ApiOperation(value = "添加商品到购物车", notes = "添加商品到购物车", httpMethod = "POST")
    @PostMapping(value = "getShopCatList")
    public FoodResultJson getShopCatList(@RequestParam String userId,
                                         @RequestBody ShopCatVo shopcatBO,
                                         HttpServletRequest request,
                                         HttpServletResponse response) {

        if (StringUtils.isBlank(userId)) {

            FoodResultJson.errMap("");

        }

        System.out.println("打印前端cookie存储的数据，传送到后端------------O(∩_∩)O哈哈~------------" + shopcatBO);

        //TODO 用户登录的状态进行，添加商品到购物车，会同时在后端同步到redis缓存
        return FoodResultJson.ok();
    }


    @ApiOperation(value = "删除购物车中商品信息", notes = "删除购物车中商品信息", httpMethod = "POST")
    @PostMapping(value = "del")
    public FoodResultJson del(@RequestParam String userId,
                              @RequestParam String itemSpecId,
                              HttpServletRequest request,
                              HttpServletResponse response) {

        if (StringUtils.isBlank(userId) || StringUtils.isBlank(itemSpecId)) {

            FoodResultJson.errMap("");

        }

        System.out.println("购物车删除商品信息，传送到后端------------O(∩_∩)O哈哈~------------用户的id为:" + userId);

        //TODO 用户登录的状态进行删除购物车的数据，同时在后端同步到redis对数据进行移除
        return FoodResultJson.ok();
    }


}
